<style>
.queue{margin-top:20px;}
.queue .queue_list{display:inline-block; position:relative; width:150px; height:150px; border-radius:100%; margin:0 20px 20px 0; color:#FFF;}
.queue .queue_list .name{display:inline-block; width:150px; height:90px; line-height:90px; text-align:center; font-size:20px; font-weight:bold;}
.queue .queue_list .status{display:inline-block; width:150px; height:30px; line-height:30px; text-align:center; font-size:16px;}
.queue .queue_list .button{position:absolute; display:none; top:0px; right:0px; width:35px; height:35px; text-align:center; line-height:35px; font-size:22px; border-radius:40px; background:rgba(0,0,0,.3);}
.queue .queue_list:hover .button{display:block;}
.queue .queue_list:hover .button:hover{background:#000}
.table-qrcode.panel{display:inline-block; margin-right:20px; float:left}
.table-qrcode.panel .panel-heading{text-align:center;font-size:16px; padding: 7px; margin-bottom: 0}
.table-qrcode.panel .panel-body div.qrcodetable{width:150px; height:150px; border-radius:100%;}
.table-qrcode.panel .panel-body div.qrcodetable img{width: 150px; }
.popup {
    position: fixed;
    background: rgba(0, 0, 0, 0.5) none repeat scroll 0 0;
    width: 100%;
    height: 100%;
    left: 0;
    top: 0;
    z-index: 1000;
    transition: all 1s;
    -moz-transition: all 1s; /* Firefox 4 */
    -webkit-transition: all 1s; /* Safari 和 Chrome */
    -o-transition: all 1s; /* Opera */
}
.popup .popup-body {
    position: absolute;
	width: 100%;
    height: 100%;
}
.popup .popup-body .popup-top {
    position: absolute;
    top: 0;
    width: 100%;
    background: #fff;
	border-bottom-left-radius: 0.5rem;
    border-bottom-right-radius: 0.5rem;
    height: auto;
}
.popup .popup-body .popup-center {
    position: absolute;
    transform : translate3d(-50%,-50%,0);
    top: 50%;
	left:50%;
	width:800px;
	max-height:1000px;
    background: #fff;
    border-radius: 0.5rem;
	padding:15px 0;
    height: auto;
}
.popup .popup-body .popup-bottom {
    position: absolute;
	width:100%;
    bottom: 0;
    background: #fff;
	min-height:800px;
    height: auto;
	border-top-left-radius:0.5rem;
	border-top-right-radius:0.5rem;
}
.popup .popup-body .fui-page-title{
    font-size: 0.8rem;
    text-align: center;
    margin-top: 3.3rem
}
.popup .popup-body .fui-page-subtitle{
    color: #999;
    text-align: center;
    width: 11rem;
    margin: 0.6rem auto
}
.popup .popup-body .subtitle{
    display: -webkit-box;
    font-size: 0.75rem
}
.popup .popup-body .popup-center .block, .popup .popup-body .popup-top .block{
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    margin: 0;
    border-top-left-radius: 0;
    border-top-right-radius: 0;
	border-bottom-left-radius: 2rem;
    border-bottom-right-radius: 2rem;
    height: 2.1rem
}
.popup .popup-body .popup-center .closed, .popup .popup-body .popup-top .closed{
	font-size:30px;color:#fff;position: absolute;top:100%;left:50%;margin-left:-15px;z-index:10
}
.popup .popup-body .popup-bottom .block{
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    margin: 0;
    height: 2.1rem
}
.popup .popup-body .popup-bottom .closed{
	font-size:30px;color:#ddd;position: absolute;top:0;right:15px;z-index:10
}
.c{text-align:center}
</style>
<ul class="nav nav-tabs">
	<li class="active"><a href="javascript:;" ng-click="access_json('list')">桌台列表</a></li>
	<li><a href="javascript:;" ng-click="access_json('edit')">添加桌台</a></li>
</ul>
<div class="panel-body" style="padding-top:2px">
		<div class="alert alert-warning">
			将如下桌台二维码打印并分别贴在对应桌台上，即可实现扫码下单的功能。微信用户到店后只需拿起微信轻轻一扫，即可实现全自动点菜下单。<br>
		</div>
		<div class="alert alert-warning">
			如果小程序二维码扫码无效，需移步：站点设置-微信小程序-绑定小程序（本小程序需要已经在小程序官方，发布成功的，才有效）。<br>
		</div>
		<div class="alert alert-warning">
			【<red>温馨提示</red>】：下面的二维码是活码（在二维码图片不变的情况下，扫码结果会根据上面《门店餐桌二维码action》设置而改变！）；
		</div>
		<div class="row" style="padding:10px 0">
			<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 right-label">指向场景餐桌二维码?</label>
					<div class="col-xs-12 col-sm-8 col-lg-9" >
						<div class="radio radio-inline" ng-repeat="(value,dtitle) in pagedata.tableactions">
							<label>
								<input type="radio" value="{{dtitle.id}}" ng-model="pagedata.store.tableaction"/>{{check_show_lang(dtitle.title)}}
							</label>
						</div>
						<div class="help-block">【<red>如何指向不同的场景餐桌？两种方法</red>】：1、门店管理--门店设置--门店餐桌二维码action；2、本地设置门店餐桌指定（优先级最高）</div>
					</div>
			</div>
		<button class="btn btn-primary ng-binding" ng-click="check_form();post(pagedata.store,'tableset')">提交</button>
		</div>
		<ul class="nav nav-tabs" ng-if="pagedata.groups">
				<li ng-class="{'active':pagedata.params.group_id==0}"><a href="javascript:;" ng-click="pagedata.params.group_id=0;tool.get_list('jy_weishop/store.s_item.s_table/list/',true);">全部</a></li>
				<li ng-repeat="tab in pagedata.groups" ng-class="{'active':pagedata.params.group_id==tab.id}">
				<a href="javascript:;" ng-click="pagedata.params.group_id=tab.id;tool.get_list('jy_weishop/store.s_item.s_table/list/',true);">{{tab.title}}</a>
				</li>
		</ul>
		<div style="margin-top:20px">
			<div class="panel panel-default table-qrcode" ng-repeat="item in pagedata.list">
						<div class="panel-heading">
							<a href="">{{item.title}}</a>({{item.groupname}})
							<a class="pull-right" href="javascript:" ng-click="post({},'del','id='+item.id,'','确认删除吗？')">&nbsp <i class="fa fa-trash-o"></i></a>
							<a class="pull-right" href="javascript:" ng-click="access_json('//edit/id='+item.id)">&nbsp <i class="fa fa-edit"></i></a>
						</div>
						<div class="panel-body c">
							<!--<span class="qrcodetable" style="width:150px;margin:auto" id="qrcode-{{$index}}" ng-init="tool.qr(item.url,'qrcode-'+$index)"></span>-->
							<div class="label-warning" ng-if="item.status ==0" style="width：100%;height:70px;line-height:70px;text-align:center;color:#fff;">未启用</div>
							<div class="label-info" ng-if="item.status ==1 && item.busy ==0" style="width：100%;height:70px;line-height:70px;text-align:center;color:#fff;font-size:20px;font-weight:bold;">空闲中</div>
							<div class="label-warning" ng-if="item.status ==1 && item.busy ==1" style="width：100%;height:70px;line-height:70px;text-align:center;color:#fff;font-size:20px;font-weight:bold;">已入座</div>
							<div class="label-danger" ng-if="item.status ==1 && item.busy ==2" style="width：100%;height:70px;line-height:70px;text-align:center;color:#fff;font-size:20px;font-weight:bold;">未结账</div>
							<div class="label-success" ng-if="item.status ==1 && item.busy ==3" style="width：100%;height:70px;line-height:70px;text-align:center;color:#fff;font-size:20px;font-weight:bold;">已结账</div>
						</div>
						<div class="panel-footer clearfix">
							<a class="pull-left" style="padding-right:3px" href="javascript:" ng-click="pagedata.wxappcode=item.wxappcode;pagedata.ewmurl=item.url;pagedata.showewm=true"><span class="label label-info">二维码</span></a>
							<a class="pull-left" href="javascript:" ng-click="clip(item.url)"><span class="label label-info">链接</span></a>
							<a class="pull-right" ng-if="item.busy !=0" href="javascript:" ng-click="post({},'/store.s_item.s_table/clear/','id='+item.id,'','确认清台吗，客户不想用餐了？清台后订单将被取消！')">&nbsp <span class="label label-warning">清台</span></a>
						</div>
						<div class="panel-footer clearfix">
							<a class="pull-left" href="javascript:"  ng-click="pagedata.showfanjie=true;pagedata.getfanjie(item.id)"><span class="label label-info">反结账</span></a>
							<a class="pull-left" ng-if="item.busy !=4" href="javascript:" ng-click="pagedata.showhebing=true;pagedata.hetableid1=item.id" style="margin-left:6px"><span class="label label-warning">合并</span></a>
							<a class="pull-right" ng-if="item.status ==1 && item.busy !=0 && item.busy !=4" href="javascript:" ng-click="access_json('/store.s_item.s_posgoods//tableid='+item.id)"><span class="label label-success">{{item.busy==1?'代客点餐':'查看订单'}}</span></a>
							<a class="pull-right" ng-if="item.status ==1 && item.busy ==0" href="javascript:" ng-click="pagedata.showkaitai=true;pagedata.nowitemid=item.id;pagedata.nowitemindex=$index"><span class="label label-success">开台</span></a>
							<a class="pull-right" ng-if="item.busy ==4"><span class="label label-success">被[{{item.hebingtitle}}]合并</span></a>
						</div>
			</div>
		</div>
</div>
<div ng-include="sys_html('common/page',true)"></div>
<div ng-if="pagedata.showewm" class="popup">
	<div class="popup-body">
		<div class="popup-center" style="padding-top:1rem;padding-bottom:1rem;width:660px;height:auto;">
			<i class="closed icon icon-cuowu" ng-click="pagedata.showewm=false"></i>
			<div class="fui-cell-title c" style="padding:10px 50px">
				H5二维码/小程序二维码
			</div>
			<div class="col-jy" style="padding:10px;width:100%">
					<div class="col-jy-6 c">
						<span class="qrcodetable"  id="qrcode-h5" ng-init="tool.qr(pagedata.ewmurl,'qrcode-h5',200)"></span>
						<div style="margin-top:10px"><a class="c label label-info" href="javascript:" ng-click="clip(pagedata.ewmurl)">复制链接</a></div>
					</div>
					<div class="col-jy-6 c">
						<img class="qrcodetable" ng-src="{{tomedia(pagedata.wxappcode) ||'../core/resource/images/no-wxapp.png'}}" style="width:200px;margin:auto">
						<div style="margin-top:10px">
							<a ng-if="pagedata.wxappcode" class="c label label-info" href="javascript:" ng-click="clip(pagedata.wxappcode)">复制图片地址</a>
							<a ng-if="!pagedata.wxappcode" class="c label label-info">暂无小程序</a>
						</div>
					</div>
			</div>
		</div>
	</div>
</div>
<div ng-if="pagedata.showkaitai" class="popup">
	<div class="popup-body">
		<div class="popup-center" style="padding-top:1rem;width:660px;height:auto;">
			<i class="closed icon icon-cuowu" ng-click="pagedata.showkaitai=false"></i>
			<div class="fui-cell-title c" style="padding:10px 50px">
				手动帮客户开台！
			</div>
			<div class="fui-cell-title" style="padding:10px 50px">
					<div class="input-group">
					<div class="input-group-addon">用餐人数</div>
						<input type="text" class="form-control" ng-model="pagedata.post.usernum"/>
					</div>
			</div>
			<div class="fui-cell-title c" style="padding-top:20px">
				<button class="btn btn-primary" style="width:200px;border-radius:20px;font-size:18px;" href="javascript:" ng-click="pagedata.tokaitai();">确认开台</button>
			</div>
		</div>
	</div>
</div>
<div ng-if="pagedata.showhebing" class="popup">
	<div class="popup-body">
		<div class="popup-center" style="padding-top:1rem;width:660px;height:auto;">
			<i class="closed icon icon-cuowu" ng-click="pagedata.showhebing=false"></i>
			<div class="fui-cell-title c" style="padding:10px 50px">
				只能合并空闲中/已入座的桌台！
			</div>
			<div class="fui-cell-title" style="padding:10px 50px">
					<div class="input-group">
					<div class="input-group-addon">合并桌台</div>
						<select class="form-control" name="paytype" id="paytype" ng-model="pagedata.hetableid2index" autocomplete="off">
							<option ng-repeat="op in pagedata.list" ng-if="op.busy<=1" ng-selected="pagedata.hetableid2index==$index" value="{{$index}}">{{op.title}}</option>
						</select>
					</div>
			</div>
			<div class="fui-cell-title c" style="padding-top:20px">
				<button class="btn btn-primary" style="width:200px;border-radius:20px;font-size:18px;" href="javascript:" ng-click="pagedata.tohebing();">提交</button>
			</div>
		</div>
	</div>
</div>
<div ng-if="pagedata.showfanjie" class="popup">
	<div class="popup-body">
		<div class="popup-center" style="padding-top:1rem;width:660px;height:auto;">
			<i class="closed icon icon-cuowu" ng-click="pagedata.showfanjie=false"></i>
			<div class="fui-cell-title c" style="padding:10px 50px">
				只显示最近的10个订单，方便做《反结账》！
			</div>
			<div class="fui-cell-title" style="padding:10px 50px">
					<div class="input-group">
					<div class="input-group-addon">选择订单</div>
						<select class="form-control" name="paytype" id="paytype" ng-model="pagedata.fanjieorderid" autocomplete="off">
							<option ng-repeat="op in pagedata.fanjieorders" ng-selected="pagedata.fanjieorderid==op.id" value="{{op.id}}">{{op.title}}</option>
						</select>
					</div>
			</div>
			<div class="fui-cell-title c" style="padding-top:20px">
				<button class="btn btn-primary" style="width:200px;border-radius:20px;font-size:18px;" href="javascript:" ng-click="pagedata.showfanjie=false;pagedata.showtofanjie=true;pagedata.tofanjie();">前往操作该订单</button>
			</div>
		</div>
	</div>
</div>
<div ng-if="pagedata.showtofanjie" class="popup">
	<div class="popup-body">
		<div class="popup-center" style="padding-top:1rem;width:660px;height:auto;">
			<i class="closed icon icon-cuowu" ng-click="pagedata.showtofanjie=false"></i>
			<div class="phone-main" style='width:auto;padding:10px;' valign='top'>
				<div class="diy-phone" style='width:auto;'>
					<div class="phone-body">
					<div class="phone-main ui-sortable" id="phone">
					<div>
						 <div ng-if="pagedata.oldorder.id" class="fui-cell-title">
							<span class="bold">已下单商品</span>
						</div>
						<div ng-if="pagedata.oldorder.id">
							<div class="table table-hover" id="native-scroll" style="min-width:100%;">
								<div class="row" style="margin:5px;font-size:16px;color:#f60"><span class="col-sm-8">商品名称</span><span class="col-sm-2">数量</span><span class="col-sm-2">单价</span></div>
								<div style="overflow-y:scroll;max-height:300px">
								<div class="row" ng-repeat="(key,item) in pagedata.oldorder.goods">
									<a ng-class="{'row margin0':1,'selected':pagedata.index==$index}" href="javascript:" ng-click="pagedata.editdata=item;pagedata.index=$index;">
									<div ng-class="{'row margin0':1,'selected':pagedata.index==$index}" style="padding:10px 0;border-bottom: 1px solid #d9d9d9" ng-if="item.optionid==0">
									<div class="col-sm-8">{{item.title}}</div>
									<div class="col-sm-2 total">{{item.total}}</div>
									<div class="col-sm-2">¥<font>{{item.price}}</font></div>
									</div>
									<div ng-class="{'row margin0':1,'selected':pagedata.index==$index}" style="padding:10px 0;border-bottom: 1px solid #d9d9d9" ng-if="item.optionid>0">
									<div class="col-sm-8">{{item.title}}-[{{item.selespename}}]</div>
									<div class="col-sm-2 total">{{item.total}}</div>
									<div class="col-sm-2">¥<font>{{item.price}}</font></div>
									</div>
									</a>
									<div ng-if="pagedata.editdata.id>0 && pagedata.index==$index" class='fui-list c' style="background:#f2f2f2;padding:0.2rem 0.3rem">
										<a href="javascript:" class='fui-list-inner' ng-click="pagedata.tuicai();">
											<i class="icon icon-shanchu1" style="font-size:0.6rem;color:#999"> 退该商品</i>
										</a>
										<a ng-if="pagedata.editdata.price>0" href="javascript:" class="fui-list-inner" ng-click="pagedata.songcai()">
											<i class="icon icon-zidingyileimu" style="font-size:0.6rem;color:#999"> 赠送该商品</i>
										</a>
									</div>
								</div>
								</div>
							</div>
						</div>
						<div class="fui-cell-title">
							<div class="bold">合计商品价格:<strong class="text-danger" id="goodsprice">{{pagedata.oldorder.goodsprice}}</strong></div>
						</div>
				</div>
				<form action="" method="post" class="form-horizontal form" enctype="multipart/form-data" id="form1">
					<div class="panel panel-default">
						<div class="panel-heading">
							<div class="row-fluid">
								<div class="span3 control-group">
									<span class="bold">用户信息</span>
								</div>
							</div>
						</div>
						<div class="panel-body">
							<div class="form-group">
								<label class="col-xs-12 col-sm-2 col-md-2 col-lg-3 control-label">手机号码</label>
								<div class="col-sm-10 col-lg-9">
								<div class="input-group">
										<input type="text" class="form-control" ng-model="pagedata.oldorder.mobile" readonly/>
										<div class="input-group-addon">人数</div>
										<input type="text" class="form-control" ng-model="pagedata.oldorder.api_data.usernum" readonly/>
								</div>
								</div>
							</div>
							<div class="form-group">
								<label class="col-xs-12 col-sm-2 col-md-2 col-lg-3 control-label">实付金额</label>
								<div class="col-sm-10 col-lg-9">
								<div class="input-group">
										<input type="text" class="form-control" ng-model="pagedata.oldorder.price" readonly/>
										<div class="input-group-addon">反结账最终金额</div>
										<input type="text" class="form-control" ng-model="pagedata.oldorder.newprice"/>
								</div>
								</div>
							</div>
						</div>
								</div>
							</form>
						</div>
					 </div>
				 </div>
				<div class="fui-cell-title c" id="submit">
						<button class="btn btn-primary" style="width:200px;border-radius:20px;font-size:18px;" href="javascript:" ng-click="pagedata.gaioldorder();">提交</button>
				</div>
			</div>
		</div>
	</div>
</div>
<audio id="openvoice" controls preload="auto" style="display:none;">
	<source src="../core/resource/images/neworder.mp3"></source>
</audio>
<div ng-if="pagedata.show_bottomloading" id="msg-bottomloading">
	<a href="javascript:;" ng-click="pagedata.show_bottomloading=false"><i class="fa fa-times"></i></a>
	<div class="msg_text">
		您有[{{pagedata.newuptable.title}}]桌台有更新！详情刷新页面查看桌台列表！
	</div>
</div>
<script type="text/javascript">
scope.pagedata.tohebing=function(){
	if(!scope.pagedata.hetableid2index && scope.pagedata.hetableid2index!=0){
		scope.message('请选择桌台！','error');
	}
	scope.pagedata.hetableid2=scope.pagedata.list[scope.pagedata.hetableid2index].id;
	scope.confirm({
		'message':'确认要把该桌台合并过来？',
		'success':function(){
			scope.post_json('jy_weishop/store.s_item.s_table/hebing/',{'hetableid1':scope.pagedata.hetableid1,'hetableid2':scope.pagedata.hetableid2},function(res){		
				scope.message('操作成功！');
				scope.pagedata.showhebing=false
				scope.pagedata.list[scope.pagedata.hetableid2index].busy=4;
				scope.$evalAsync();
			});
		},
		'fail':function(){}
	});
}
scope.pagedata.getfanjie=function(tableid){
	scope.get('jy_weishop/store.s_item.s_table/getfanjie/tableid='+tableid,function(res){		
			scope.pagedata.fanjieorders=res.list
			scope.$evalAsync();
	});
}
scope.pagedata.tofanjie=function(){
	scope.get('jy_weishop/store.s_item.s_table/getoldorder/orderid='+scope.pagedata.fanjieorderid,function(res){		
			scope.pagedata.oldorder=res.oldorder
			scope.$evalAsync();
	});
}
scope.pagedata.tokaitai=function(){
	scope.post_json('jy_weishop/store.s_item.s_table/kaitai/tableid='+scope.pagedata.nowitemid+'&usernum='+scope.pagedata.post.usernum,{},function(res){		
		scope.pagedata.list[scope.pagedata.nowitemindex].busy=1;
		scope.message('开台成功！');
		scope.$evalAsync();
	});
}
//刷新总数和总价
scope.pagedata.refresh=function(){
	scope.$evalAsync();
}
scope.pagedata.tuicai=function(){
	scope.confirm({
		'message':'确认要退了该商品吗？',
		'success':function(){
			if(scope.pagedata.oldorder.status>0){
				scope.message('已结账订单不能退商品！','error');
				return false;
			}
			scope.post_json('jy_weishop/store.s_item.s_posgoods/tuicai/',scope.pagedata.editdata,function(res){
				scope.pagedata.oldorder.goodsprice -=scope.pagedata.oldorder.goods[scope.pagedata.index].total_price*1
				scope.pagedata.oldorder.newprice -=scope.pagedata.oldorder.goods[scope.pagedata.index].total_price*1
				scope.pagedata.oldorder.goods.splice(scope.pagedata.index,1);
				scope.pagedata.refresh()
			});
			
		},
		'fail':function(){}
	});
}
scope.pagedata.songcai=function(){
	scope.confirm({
		'message':'确认要赠送该商品吗？',
		'success':function(){
			if(scope.pagedata.oldorder.status>0){
				scope.message('已结账订单不能赠送商品！','error');
				return false;
			}
			scope.post_json('jy_weishop/store.s_item.s_posgoods/songcai/',scope.pagedata.editdata,function(res){		
				scope.pagedata.oldorder.goods[scope.pagedata.index].isgift=1;
				scope.pagedata.oldorder.goodsprice -=scope.pagedata.oldorder.goods[scope.pagedata.index].total_price*1
				scope.pagedata.oldorder.newprice -=scope.pagedata.oldorder.goods[scope.pagedata.index].total_price*1
				scope.pagedata.oldorder.goods[scope.pagedata.index].price=0;
				scope.pagedata.oldorder.goods[scope.pagedata.index].total_price=0;
				scope.pagedata.refresh()
			});
		},
		'fail':function(){}
	});
}
scope.pagedata.gaioldorder=function(){
	scope.confirm({
		'message':'确认要反结账改单？改单后金额：￥'+scope.pagedata.oldorder.newprice,
		'success':function(){
			scope.post_json('jy_weishop/store.s_item.s_table/gaioldorder/',{'newprice':scope.pagedata.oldorder.newprice,'id':scope.pagedata.oldorder.id});
		},
		'fail':function(){}
	});
}
scope.pagedata.openvoice=function(type){
	var voicetime = 0;
    var openvoice;
	for(var i = 1;i<=100;i++){
		clearInterval(i);
	}
	if(type){
		 openvoice = setInterval(() => {
			/*if(!scope.main.isopenvoice){
				clearInterval(openvoice);
				return false;
			}*/
			scope.get('jy_weishop/store.s_item.s_table/getnew/group_id='+scope.pagedata.params.group_id,function(res){
						//console.log('openvoice');console.log(res);
						if(res!='none'){
							console.log('getshow');
							scope.pagedata.newuptable=res
							angular.forEach(scope.pagedata.list,function(table){
								if(table.id==res.id){
									table.busy=res.busy;
									table.status=res.status;
								}
							 });
							voicetime ++;
							$("#openvoice")[0].play();
							scope.pagedata.show_bottomloading=true;
							scope.$evalAsync();
						}
			});
		}, 3000);
	}
}
scope.pagedata.openvoice(1);
</script>